<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>淘宝返利和券查询</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">

	<style type="text/css" >
		.nav-font-c{
			color: #007bff;
		}
	</style>
</head>
<body>
<div class="container-fluid " style="height: 42px;background: #8bcc93">
  	<div class="container pt-2" style="color: #fff">
  		<div class="float-left" style="font-size: 12px;">
  				<span class="un-login-user-name" style="font-size:13px;cursor:pointer;" >亲 ~~ 您好</span>
  				<span class="login-userSpan" style="font-size:12px;cursor:pointer;display: none;" > 您好 : &nbsp;
			 		<span class="login-user-name" style="font-size: 14px;color: #0062cc;cursor:pointer;"> </span>
				</span>
  		</div>
		<div class="float-right">

			<div class="fl-r-unlogin" >
				<span class="user-help" style="font-size: 13px;color: #0062cc;cursor:pointer;">帮助</span>
				<span id="user-longin" class="ml-3" style="font-size: 13px;color: #0062cc;cursor:pointer;" >登录</span>
				<span id="user-register" style="font-size: 13px;color: #0062cc;cursor:pointer;"  class="ml-3">注册</span>
			</div>
			<div class="fl-r-login" style="display: none;" >
				<span class="user-help" style="font-size: 13px;color: #0062cc;cursor:pointer;">帮助</span>
				<span id="user-relongin" style="font-size: 13px;color: #0062cc;cursor:pointer;" class="ml-3" >重新登录</span>
			</div>
		</div>

		<div class="float-none"></div>
	</div>
</div>


<div class="container mt-2">


		<ul class="nav nav-tabs" id="myTab" role="tablist">
		  <li class="nav-item index-html">
		    <a class="nav-link active"  data-toggle="tab"  role="tab" >首页</a>
		  </li>
		  <li class="nav-item nav-font-c search-order-html">
		    <a class="nav-link " data-toggle="tab" role="tab" >订单查询</a>
		  </li>
		  <li class="nav-item nav-font-c settlement-html">
		    <a class="nav-link"  data-toggle="tab"  role="tab"  >结算</a>
		  </li>
		</ul>

  <!-- Content here -->
  <form>

	  <div class="form-group mt-3">
	    <label for="exampleFormControlTextarea1" ><span style="color: #333;font-size: 14px;">请您输入商品淘口令或链接</span></label>
	    <textarea class="form-control" id="old-user-TKL" rows="3"></textarea>
	  </div>

	  <div class="form-group">
	    <button type="button" id="btn-sendTKL" class="btn btn-primary btn-block">点击生成返利淘口令或链接</button>
	  </div>
	  <div class="form-group">
	    <div class="alert alert-success" style="display: none;" role="alert">
		  <p class="mb-0">请求成功</p>
		  <span class="commission-msg" style="color: red"></span>
		</div>
	  </div>

	  <div class="form-group">
	    <label for="exampleFormControlTextarea1"><span style="color: #333;font-size: 14px;">复制下面返利淘口令或链接去下单</span></label><br />
	    <span style="color: red;font-size: 13px;"> 淘口令或链接包含优惠券哟</span>

	    <textarea class="form-control" id="new-my-TKL" rows="2"></textarea>
	  </div>

  </form>

<span style="color: #666;font-size: 14px;">没有注册请加我微信，发送你的订单号找我返利。</span><br />
<span style="color: #666;font-size: 14px;">微信:c615879110  昵称：壬  </span><br />
<span style="color: #666;font-size: 14px;">QQ群：436786651</span><br />


<span style="color: #666;font-size: 14px;">只有确认收货后，才会有返利哟</span><br />
<span style="color: #666;font-size: 12px;">系统会持续升级.请您关注</span>
</div>

<!-- jQuery first, then Tether, then Bootstrap JS.  B-->

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>

<!-- jQuery first, then Tether, then Bootstrap JS. E -->

<script>
var isLogin = "";
(function(){
	//去左右空格;
	function trim(s){
	    return s.replace(/(^\s*)|(\s*$)/g, "");
	}
	function send(){
		$("#new-my-TKL").val('');
		$(".alert-success").hide();
		var yTKL = $("#old-user-TKL").val();
		yTKL = yTKL.replace(/&/g, 'AAAAA');
		var tklUrl = "/sendTKL/tklConvertTkl?token="+yTKL;
		yTKL = trim(yTKL);
		if(!yTKL || yTKL.length == 0){
			alert("不能为空，请您输入商品淘口令！");
			return;
		}
		$("#btn-sendTKL").off().text("正在请求，请等候......");
		$.ajax({
		   type: "GET",
		   url: tklUrl,
		   dataType:"json",
		   success: function(msg){
		   		$("#btn-sendTKL").off().on("click", send).text("点击生成返利淘口令");
			   	console.info(msg)
			   	//JSON.stringify(msg)
			   	//var body =  JSON.parse(msg.body);
			   	//console.info(body);
			   	if(msg.code == 200){
			   		if(msg.body.errcode == 0 ){
			   			if(msg.body.token){
			   					$(".commission-msg").text('返利金额 ：'+msg.body.commission);
			   					$("#new-my-TKL").val(msg.body.token);
			   			}else{
			   					$(".commission-msg").text('返利金额 ：支付金额的'+msg.body.commissionRate+"%");
			   					$("#new-my-TKL").val(msg.body.clickUrl);
			   			}


					   	$(".alert-success").show();

			   		}else{
			   			alert("提示: "+msg.body.errmsg);
			   		}

			   	}else{
			   		alert(msg.msg)
			   	}

		   },
		   error: function(XMLHttpRequest, textStatus, errorThrown) {
				// alert(XMLHttpRequest.status);
				// alert(XMLHttpRequest.readyState);
				// alert(textStatus);
				$("#btn-sendTKL").off().on("click", send).text("点击生成返利淘口令");
				alert("请求失败！请联系管理员");
		   }
		})
	}

	$("#btn-sendTKL").off().on("click", send);
	$(".search-order-html").off().on("click", function(){
			if(isLogin){
				window.location.href='search-order.html';
			}else{
				alert("登录后才可用");
				location.reload();
			}
			
	});

	$(".user-help").off().on("click", function(){

			window.location.href='use-help.html';
	});


	$("#user-longin").off().on("click", function(){

			window.location.href='longin-register.html';
	});
	$("#user-relongin").off().on("click", function(){

			window.location.href='longin-register.html';
	});
	$("#user-register").off().on("click", function(){

			window.location.href='longin-register.html?regPar=reg';
	});
	$(".settlement-html").off().on("click", function(){
			if(isLogin){
				window.location.href='settlement.html';
			}else{
				alert("登录后才可用");
				location.reload();
			}

			
	});
	$(".login-user-name").off().on("click", function(){

			window.location.href='user-info.html';
	});

}())



function init (){
	$.ajax({
		   type: "POST",
		   url: "/mytk/tklUser/webToken",
		   dataType:"json",
		   success: function(msg){

			   	console.info(msg)

			   	if(msg.code == 200){

			   		$('.un-login-user-name').hide();
			   		$('.login-user-name').text(msg.body.name);

			   		$('.login-userSpan').show();

			   		$('.fl-r-unlogin').hide();
			   		$('.fl-r-login').show();
			   		isLogin  =  msg.body.name;

			   	}else{
			   		//alert(msg.msg)
			   	}
		   },
		   error: function(XMLHttpRequest, textStatus, errorThrown) {

				alert("请求失败！请联系管理员");
		   }
		})

}

init();
</script>
</body>
</html>